<?php
require_once "config.php";
require_once dirname(__FILE__). '/util/connection.class.php';
require_once dirname(__FILE__). '/util/util.php';
set_time_limit(60*60);
ini_set('memory_limit', '512M');

$g_start = microtime(true);

$dbconn = Connection::getInstance();

$users = getUsers($dbconn);
$i = 1;
foreach ($users as $user)
{
	$emails = getEmails($dbconn, $user['email']);
	foreach ($emails as $email)
	{
		echo $i . "\t" . $email['email_type'] . "\t". $user['email'] . "\t". long2ip($user['ip']) . "\t". date('Y-m-d H:i:s', $user['created']). "\t". $email['result'] . "\n";
		$i++;
	}
}

echo 'Totally: '. (microtime(true) - $g_start) . " seconds \n";
echo "memory: " . memory_get_peak_usage() . " bytes \n";

function getEmails($db, $email)
{
	$sql = "select email_type, result from emails where sendto=?";
	try
	{
		return $db->query($sql, array($email));
	}
	catch (Exception $e)
	{
		QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
		throw new Model_Exception($e->getMessage(), $e->getCode());
	}
}
function getUsers($db)
{
	$sql = "select * from users where pla='186225'";
	try
	{
		$ret = $db->query($sql);
		return $ret;
	}
	catch (Exception $e)
	{
		QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
		throw new Model_Exception($e->getMessage(), $e->getCode());
	}
}
?>